﻿''' <summary>
''' Handles the Creation and Cleanup of Temp Files used by the Program
''' </summary>
''' <remarks></remarks>
''' <features></features>
''' <stepthrough>Will be Enabled Soon</stepthrough>
Public Class TempFileNameService
    Implements IDisposable
    Private Shared m_files As New List(Of String)()

    ''' <summary>
    ''' Stores(In <see cref="m_files"/>  and Returns the Name of A New Temp File Using the Given <paramref name="extension">File Extension</paramref>
    ''' </summary>
    ''' <param name="extension"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    ''' <stepthrough></stepthrough>
    Public Shared Function GetNewFileName(ByVal extension As String) As String
        Dim tempFile As String = IO.Path.GetTempFileName()
        Dim requestedFile As String = tempFile & "." & extension.Replace(".", "")
        m_files.Add(tempFile)
        m_files.Add(requestedFile)
        Return requestedFile
    End Function

    ''' <summary>
    ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    ''' </summary>
    ''' <remarks></remarks>
    ''' <stepthrough></stepthrough>
    Public Shared Sub CleanUp()
        For Each file__1 As String In m_files
            Try
                IO.File.Delete(file__1)
            Catch
            End Try
        Next
        m_files = New List(Of String)()
    End Sub

    ''' <summary>
    ''' Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
    ''' </summary>
    Public Sub Dispose() Implements IDisposable.Dispose
        CleanUp()
    End Sub

End Class